#include <iostream>
#include <thread>
#include <mutex>
using namespace std;
//void print(int n, mutex* mtx)
//{
//	(*mtx).lock();
//	for (int i = 0; i < n; ++i)
//	{
//		cout <<this_thread::get_id()<<":" << i << endl;
//	}
//	(*mtx).unlock();
//}
mutex mtx;
void Print(int n, int& count)
{
	mtx.lock();
	for (int i = 0; i < n; ++i)
	{
		cout << this_thread::get_id() << ":" << i << endl;
		cout << count++ << endl;
	}
	mtx.unlock();
}
int main()
{
	//mutex m;
	int count = 0;
	thread t1(Print,10,std::ref(count));
	thread t2(Print,10,std::ref(count));
	t1.join();
	t2.join();
		
	cout << count << endl;
	return 0;
}